// pages/service/balance-management/index.js
var api = require("../../../../api.js"),
  app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    site: '',
    actions: [{
        name: '提现到银行卡',
        subname: '提现到默认绑定的银行卡中',
        className: 'action-class',
        loading: false
      },
      {
        name: '提现到支付宝',
        subname: '提现到支付宝余额中',
        className: 'action-class',
        loading: false
      }, {
        name: '提现到余额',
        subname: '提现到微信余额中',
        className: 'action-class',
        loading: false
      }
    ],
    cancelText: '取消'
  },
  onShow: function() {

    app.pageOnLoad(this);
    var that = this;
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
      site: wx.getStorageSync('site'),
      bgurl: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background/bg.png'
    })
    app.request({
      url: api.order.balance,
      data: {
        uid: wx.getStorageSync('uid')
      },
      success: function(e) {
        if (e.code == 1) {
          that.setData({
            money: e.data
          })
        }
      }
    })
    app.request({
      url: api.order.priceMsg,
      data: {
        uid: wx.getStorageSync('uid')
      },
      success: function(e) {
        that.setData({
          datas: e.data
        })
      }
    })
    app.request({
      url: api.order.orderMsg,
      data: {
        uid: wx.getStorageSync('uid')
      },
      success: function(e) {
        that.setData({
          price: e.money
        })
      }
    })
  },
  // 开启选择器
  openActionsheet() {
    this.setData({
      'show': true
    });
  },
  // 关闭选择器
  closeActionSheet() {
    this.setData({
      'show': false
    });
  },
  // 根据选择进行调用事件
  clickAction({
    detail
  }) {
    const {
      index
    } = detail;
    this.setData({
      [`actions[${index}].loading`]: true,
      actionType: index
    });
    switch (index) {
      case 0: // 0 提现到银行卡
        wx.navigateTo({
          url: '/sd_liferuning/pages/constmer/withdraw-money/index',
        });
        break;
      case 1: // 1 提现到支付宝
        wx.navigateTo({
          url: '/sd_liferuning/pages/constmer/withdraw-ali/index?type=1',
        });
        break;
        case 2: // 1 提现到余额
          wx.navigateTo({
            url: '/sd_liferuning/pages/constmer/withdraw-wechat/index',
          });
        break;
    }
    setTimeout(() => {
      this.setData({
        [`show`]: false,
        [`actions[${index}].loading`]: false
      });
    }, 100);
  },
})